// Copyright (c) Microsoft Corporation.  All rights reserved.

#include "stdafx.h"
#include "D3D10EffectMatrixVariable.h"

using namespace Microsoft::WindowsAPICodePack::DirectX::Direct3D10;

const int MatrixSize = 16;

array<Single>^ EffectMatrixVariable::GetMatrix()
{
    array<Single>^ matrix = gcnew array<Single>(MatrixSize);
    pin_ptr<FLOAT> pinnedArray = &matrix[0];

    CommonUtils::VerifyResult(GetInterface<ID3D10EffectMatrixVariable>()->GetMatrix(pinnedArray));
    return matrix;
}

array<Single,2>^ EffectMatrixVariable::GetMatrixArray(UInt32 offset, UInt32 count)
{
    array<Single, 2>^ matrix = gcnew array<Single, 2>(MatrixSize, count);
    pin_ptr<FLOAT> pinnedArray = &matrix[0, 0];

    CommonUtils::VerifyResult(GetInterface<ID3D10EffectMatrixVariable>()->GetMatrixArray(pinnedArray, offset, count));
    return matrix;
}

array<Single>^ EffectMatrixVariable::GetMatrixTranspose()
{
    array<Single>^ matrix = gcnew array<Single>(MatrixSize);
    pin_ptr<FLOAT> pinnedArray = &matrix[0];

    CommonUtils::VerifyResult(GetInterface<ID3D10EffectMatrixVariable>()->GetMatrixTranspose(pinnedArray));
    return matrix;
}

array<Single,2>^ EffectMatrixVariable::GetMatrixTransposeArray(UInt32 offset, UInt32 count)
{
    array<Single, 2>^ matrix = gcnew array<Single, 2>(MatrixSize, count);
    pin_ptr<FLOAT> pinnedArray = &matrix[0, 0];

    CommonUtils::VerifyResult(GetInterface<ID3D10EffectMatrixVariable>()->GetMatrixTransposeArray(pinnedArray, offset, count));    
    return matrix;
}

void EffectMatrixVariable::SetMatrix(array<Single>^ data)
{
    pin_ptr<FLOAT> matrix= &data[0];
    CommonUtils::VerifyResult(GetInterface<ID3D10EffectMatrixVariable>()->SetMatrix(matrix));
}

void EffectMatrixVariable::SetMatrixArray(array<Single,2>^ data, UInt32 offset)
{
    pin_ptr<FLOAT> matrix = &data[0, 0];
    CommonUtils::VerifyResult(GetInterface<ID3D10EffectMatrixVariable>()->SetMatrixArray(matrix, static_cast<UINT>(offset), static_cast<UINT>(data->Rank)));
}

void EffectMatrixVariable::SetMatrixTranspose(array<Single>^ data)
{
    pin_ptr<FLOAT> matrix= &data[0];
    CommonUtils::VerifyResult(GetInterface<ID3D10EffectMatrixVariable>()->SetMatrixTranspose(matrix));
}

void EffectMatrixVariable::SetMatrixTransposeArray(array<Single,2>^ data, UInt32 offset)
{
    pin_ptr<FLOAT> matrix = &data[0, 0];
    CommonUtils::VerifyResult(GetInterface<ID3D10EffectMatrixVariable>()->SetMatrixTransposeArray(matrix, static_cast<UINT>(offset), static_cast<UINT>(data->Rank)));
}

